<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@ page import="com.pojo.OUser"%>
    <%@ page import="com.pojo.Statis"%>
    <%@ page import="java.util.List,java.util.Map"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%
	OUser user = (OUser) request.getAttribute("list3");
	Statis price = (Statis)request.getAttribute("price");//开盘价
	List list = (List) request.getAttribute("list");
	List list1 = (List) request.getAttribute("list1");
	String goods = (String)request.getAttribute("goods");//取得商品
	List<Map> list2 = (List<Map>) request.getAttribute("list2");//多商品下拉框
 %>
 <!doctype html>
<!-- <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd ">
 --><html>
<head>
 <base href="<%=basePath%>">   
 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
 <title>购买挂单</title>
    <meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1.0"/>
    <meta name="format-detection" content="telephone=no, email=no"/>
    <link rel="stylesheet" href="css/common.css" type="text/css"/>
    <link rel="stylesheet" type="text/css" href="css/index.css?v=1.2.2"/>
    <link rel="stylesheet" href="css/personalCenter.css?v=1.2.2" type="text/css">
    <link rel="stylesheet" type="text/css" href="lib/css/dropload.css"/>
    <link rel="stylesheet" type="text/css" href="lib/css/swiper-3.4.2.min.css" />
    <link rel="stylesheet" type="text/css" href="css/index.css"/>
    <link rel="stylesheet" href="lib/css/layer.css" type="text/css">
    <script src="lib/js/jquery-2.1.4.js" type="text/javascript" charset="utf-8"></script>
  <!-- <!--   <link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.css"> --> -->
    <!-- <script src=js/jquery.mobile-1.3.2.js></script> -->
     <!--  <script src="http://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.js"></script> -->
    
    <script src="lib/js/jquery.base64.js"></script>

    <script src="lib/js/layer.js"></script>
    
    <style type="text/css">
        .header{
            background:#f46054;
        }
        .container>section:first-of-type{
           
        }
        .tbgg{
            position: relative;
        }
        .tbgg:after{
            content: "";
            position: absolute;
            height: 0.34rem;
            border-left: 1px solid #dedede;
            right: 0;
            top: 0.23rem;
        }
        .wrapper1{
            width: 100%;
            height: 100%;
            position: absolute;
        }
        .wrapper{
            width: 100%;
            position: absolute;
            top: 0;
            bottom: 0;
            overflow-y: auto;
        }
 
        .list{
            background: #fff;
            height: 90%;
        }
        .public_listnodata{
            background: url(img/ewma.png) no-repeat center center;
            background-size: 2.67rem 2.78rem;
            background-color: #fff
        }
        .returntop{
            position: fixed;
            z-index: 99999;
            width: 0.78rem;
            right: 0.3rem;
            bottom: 1.4rem;
        }
        .notification_list .to_detail {
            width: 0.2rem;
            position: absolute;
            right: 0.3rem;
           
        }
        .mescroll-downwarp .downwarp-tip{
            margin-top: 30px;
        }
        .nodata{
            text-align: center;
        }
        .nodata img{width: 2.42rem;height:1.7rem;margin-top: 45%;}
        .nodata p{line-height: 0.6rem;}
    </style>
    <link rel="stylesheet" type="text/css" href="lib/css/mescroll.min.css"/>
    <script src="lib/js/mescroll.min.js" type="text/javascript" charset="utf-8"></script>
    <script type="text/javascript" language="javascript">
	$(document).ready(function() {	
		fun123();//页面加载下拉框的数据
		getgoodnum();
	});
</script>
    <script type="text/javascript">
    //查询商品余量
    function getgoodnum() {
		var goods = $("#select1").find("option:selected").text();
		var UserID = <%=user.getUserID()%>;
		$.ajax({
			type : 'get',
			url : 'getgoodnum.html',
			data:{'goods':goods,'UserID':UserID},
			success : function(data) {
				var html="";
				$('#yuliang').html(data);
			}
		});
	}
    
    var flag = 1;
	function main() {
		if (flag == 0)
			return;

		var url = "insertwtd.html";
		//alert("当前系统正在紧急维护,请耐心等候,预计两小时调整好");
		//return;
		var d = {};
		d.ttype=$("#select2").find("option:selected").text();
		var num = document.getElementById("num").value;
		var jiage = document.getElementById("jiage").value;
		if (jiage == '' || num == '') {
			alert("数量和价格不能为空");
			flag = 1;
			return;
		}

		/*调试价格在指导价的上下百分之十  2017/12/1  11:33 yy  */
		var openprice =<%=price.getOpenprice()%>;
		if (jiage > openprice * 1.1) {
			alert("您的价格过高,请重新输入价格");
			flag = 1;
			return;
		}
		if (jiage < openprice * 0.9) {
			alert("您的价格过低,请重新输入价格");
			flag = 1;
			return;
		}

		var consume = jiage * num;
		//alert(d.ttype + "," + jiage + "," + num + "," + consume);
		d.wcount = num;
		d.wprice = jiage;
		d.consume = consume;
		d.goods = $("#select1").find("option:selected").text();
		flag = 0;
		$.ajax({
			type : 'post',
			url : url,
			data : d,
			success : function(data) {
				//console.log(data);
				var s1 = "今天是周末哦,请工作日内进行交易哦!";
				var s2 ="您委托单的价格不在指导价的上下百分之十，请重新输入价格！";
				var s3 = "您的余额不足以购买该订单，请先充值，或者降低挂买数量！";
				var s4 = "现在还不能提交委托单哦！";
				var s5 = "您提交的所有委托单的总金额大于您拥有的余额，请降低挂买数量!";
				var s6 = "您的库存与您拥有的宝石数不符合,请尽快跟客户联系!";
				var s7 = "您冻结的数量为负，请尽快跟客户联系查询资产信息!";
				var s8 = "您的积分包数量不足，请先兑换，或者降低挂售数量！";
				var s9 = "您的委托单已提交成功";
				if (data == "untradedate") {
					alert(s1);
				} else if (data == "priceerror") {
					alert(s2);
				}else if (data == "unencash") {
					alert(s3);
				} else if (data == "untrade") {
					alert(s4);
				}else if (data == "unfinish") {
					alert(s5);
				} else if (data == "undangerous") {
					alert(s6);
				} else if (data == "djnumerror") {
					alert(s7);
				}else if (data == "unwcount") {
					alert(s8);
				} else{
					alert(s9);
				}
				flag = 1;
				qingkong();
				getgoodnum();
				window.location.reload();
			},
			error : function(jqXHR, textStatus, errorThrown) {
				flag = 1;
			}
		});
	}
	function qingkong(){
		document.getElementById("num").value='';
		document.getElementById("jiage").value='';
	}
	function clearNoNum(obj){ 
	    obj.value = obj.value.replace(/[^\d.]/g,"");  //清除“数字”和“.”以外的字符  
	    obj.value = obj.value.replace(/\.{2,}/g,"."); //只保留第一个. 清除多余的  
	    obj.value = obj.value.replace(".","$#$").replace(/\./g,"").replace("$#$","."); 
	    obj.value = obj.value.replace(/^(\-)*(\d+)\.(\d\d).*$/,'$1$2.$3');//只能输入两个小数  
	    if(obj.value.indexOf(".")< 0 && obj.value !=""){//以上已经过滤，此处控制的是如果没有小数点，首位不能为类似于 01、02的金额 
	        obj.value= parseFloat(obj.value); 
	    } 
	} 
	function clearNoNum1(obj){ 
	    obj.value = obj.value.replace(/[^\d]/g,"");  //清除“数字”和“.”以外的字符  
	 //   obj.value = obj.value.replace(/\.{2,}/g,"."); //只保留第一个. 清除多余的  
	    obj.value = obj.value.replace(".","$#$").replace(/\./g,"").replace("$#$","."); 
	    obj.value = obj.value.replace(/^(\-)*(\d+)\.().*$/,'$1$2.$3');//只能输入两个小数  
	    if(obj.value.indexOf(".")< 0 && obj.value !=""){//以上已经过滤，此处控制的是如果没有小数点，首位不能为类似于 01、02的金额 
	        obj.value= parseFloat(obj.value); 
	    } 
	} 
	function fun123(){
		var goods = '<%=goods%>';
		//alert(goods);
	    document.getElementById("select1").value = goods;
	}
	function goodsChange(){
		 //document.getElementById("select1").value = goods;
		 var goods=$("#select1").val();
		 window.location.href="appguadan.html?goods="+goods
	}
    
    function record(){
    	window.location.href="apprecord.html";
    	
    }
    </script>
</head>
<body class="notificationPage">
<div class="wrap">
    <section class="container">
        <header class="header notification_title" style="display:none;">
            <a href="appmain.html?page=1&last=5" id="f_btn"><i class="icon"></i></a>
            <span>购买挂单</span>
         </header>



        <section class="notification_list list" id="notification_list" >
	  <span style="">参考价格:<%=price.getOpenprice() %></span>
 <form name="myform" action="?action=S" method="post" onSubmit="return CheckForm();">
<div class="withdraw_content">
    <p class="sum_avai">商品余量：<span class="sp_color balance_avai" id="yuliang"></span>颗</p>
          <div class="withdrawrecord_content">
    <ul class="menu clearfix">
        <li>交易类型</li>
        <li>价格</li>
         <li>数量</li>
    </ul>
    <div id="wrapper">
        <ul class="detail">
            <% for(int i=0;i<list.size();i++){
				Map map = (Map)list.get(i);
				%>
				<li class="clearfix">
                <div class="item">
                    <span>卖</span>
                 </div>
                <div class="item">
                    <span><%=map.get("wprice") %></span>
                 </div>
                 <div class="item">
                     <span class="cancel_withdraw"><%=map.get("wcount") %></span>
                </div>
            </li>
				<%
				}
				%>
     
        </ul>
    </div>
</div>
    <div class="withdrawrecord_content">
    <ul class="menu clearfix">
        <li>交易类型</li>
        <li>价格</li>
         <li>数量</li>
    </ul>
    <div id="wrapper">
        <ul class="detail">
            <% for(int i=0;i<list1.size();i++){
				Map map = (Map)list1.get(i);
				%>
				<li class="clearfix">
                <div class="item">
                    <span>买</span>
                 </div>
                <div class="item">
                    <span><%=map.get("wprice") %></span>
                 </div>
                 <div class="item">
                     <span class="cancel_withdraw"><%=map.get("wcount") %></span>
                </div>
            </li>
				<%
				}
				%>
     
        </ul>
    </div>
</div> 
     
			  <p class="txed">
<span class="txed_title">选择商品</span>
<select name="sp" id="select1" onchange="goodsChange()"> 
<%
							for (int i =0;i<list2.size();i++) {
								Map mmp = (Map)list2.get(i);
								String selected = "";
						%>
						<option <%=selected%>><%=mmp.get("classname")%></option>
						<%
							}
						%> 
</select>      
 <span class="txgz" id="txgz_btn"> </span>
</p>		
			  <p class="txed">
<span class="txed_title">交易方式</span>
<select name="jylx" id="select2"  > 
<option value="买" selected='selected'>买</option>
<option value="卖"  >卖</option>
</select> 
 <span class="txgz" id="txgz_btn"> </span>
</p>	
 
<p class="txed">
<span class="txed_title">意向价格</span>
<input type="text" name="jiage" id="jiage"    placeholder="输入意向价格" onKeyUp="clearNoNum(this)" />
<span class="txgz" id="txgz_btn"> </span>
</p>
<p class="txed">
<span class="txed_title">买卖数额</span>
<input type="text" name="num" id="num"  placeholder="输入买卖数额" onKeyUp="clearNoNum1(this)" />
<span class="txgz" id="txgz_btn"> </span>
</p>

    
 
 <input type="button" id='bt1' class="withdraw_btn bt1" onclick="main()"  value="委托" /> 
 <input type="button"  id='bt2' class="withdraw_btn bt2" onclick="record()" value="委托记录" /> 
 <script>

  /* 	document.getElementById('bt1').addEventListener('touchstart',function (){
  		main();  		
  	});
	document.getElementById('bt2').addEventListener('touchstart',function (){
		record();
  	}); */
    </script>
</div>

 
				 
				</form>

            </div>
          
        </section>
    </section>
</div>
</body>
<script src="js/notification.js?v=1.2.2"></script>
<script src="lib/js/RainbowBridge.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript">
    setTitle(".notification_title", {'title':'通知',"theme":"1"});
</script>
</html>

